package com.wm.dao;

import com.wm.entity.RbacRole;
import com.wm.entity.RbacUser;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.mapping.FetchType;

import java.util.List;

@Mapper
public interface UserDao {

    @Insert("insert into rbac_user(account,password) values(#{account},#{password}) ")
    @Options(useGeneratedKeys = true,keyColumn = "id",keyProperty = "id")
    void insert(RbacUser user);

    @Select("select * from rbac_user")
    @Results({
            @Result(id = true,property = "id",column = "id"),
            @Result(property = "name",column = "name"),
            @Result(property = "description", column = "description"),
            @Result(property = "status", column = "status"),
            @Result(property = "perms",column = "id",many =@Many(select = "com.wm.dao.PermDao.getByRoleId",fetchType = FetchType.LAZY))

    })
    List<RbacUser> getAll(RbacUser role);
    List<RbacUser> getAll();

    @Select("select * from rbac_manager where id =#{id}")
    RbacRole selectId (Integer id);

    @Delete("delete from rbac_user where id =#{id}")
    void deleteId(Integer id);



    @Select("select * from rbac_user where account=#{account}")
    RbacUser getByAccount(String account);
}
